<?php

namespace common\models\business;

use Yii;
use yii\db\Query;

/**
 * This is the model class for table "new_business_inspection_field".
 *
 * @property string $id
 * @property string $name
 * @property string $type
 * @property string $placeholder
 * @property string $data
 * @property string $comment
 * @property integer $createtime
 */
class NewBusinessInspectionField extends \yii\db\ActiveRecord
{


    const TYPE_INPUT = 'input';
    const TYPE_SELECT = 'select';
    const TYPE_TEXTAREA = 'textarea';
    const TYPE_IMAGE = 'image';
    public static $fieldtype = [
        self::TYPE_INPUT => '输入框',
        self::TYPE_SELECT => '下拉选项',
        self::TYPE_TEXTAREA => '文本框',
        self::TYPE_IMAGE => '上传图片',
    ];


    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '巡检字段',      //用于修改了什么的显示
        'mainfield' => 'name',      //主要的显示标题的字段
        'picturefield' => [],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'new_business_inspection_field';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name','type'],'required'],
            [['name'], 'string', 'max' => 30],
            [['type'], 'string', 'max' => 20],
            [['placeholder'], 'string', 'max' => 50],
            [['eventtrigger','data'], 'string', 'max' => 1000],
            [['comment'], 'string', 'max' => 100],
            [['unit','viewwidth'],'string','max'=>10],
            [['datatype'],'string','max'=>225],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '字段名称',
            'type' => '手机端输入类型',
            'placeholder' => '提示输入项',
            'data' => '下拉框数据，以英文“,”逗号隔开',
            'comment' => '字段备注',
            'createtime' => '创建时间',
            'unit' => '单位',
            'event' => '事件（非开发人建议不改动）',
            'eventtrigger' => '触发动作（非开发人建议不改动）',
            'viewwidth' => '展示宽度',
            'default' => '默认值(如是下拉框，则默认值必须是下拉框中一个数据)',
            'isshow' => '是否手机页面展示',
            'datatype' => '输入的类型'
        ];
    }


    public static function allField(){
        $fields = \Yii::$app->cache->get('inspection_field');
        if(!$fields){
            $fields = (new  Query())->select('*')->from(NewBusinessInspectionField::tableName())->indexBy('name')->all();
            \Yii::$app->cache->set('inspection_field',$fields);
        }
        return $fields;
    }
}
